<?php
namespace app\mall_back\controller;

use app\mall_back\model\ProblemClassModel;
use app\mall_back\model\ProblemModel;
use think\admin\Controller;

class Problem extends Controller{

    /**
     * 问题管理
     * @auth true
     */
    public function index(){
        ProblemModel::mQuery()->layTable(function () {
            $this->title = '问题管理';
        });
    }

    //表单数据处理
    protected function _form_filter(array &$data){
        if ($this->request->isGet()) {
            $this->problem_class = ProblemClassModel::select();
        }

    }


    //数据列表处理
    protected function _page_filter(array &$data)
    {
        foreach ($data as $k => &$v){
            $v['problem_class'] = ProblemClassModel::where('id','=',$v['class_id'])->value('problem_class');
        }

    }

    /**
     * 添加问题
     * @auth true
     */
    public function add()
    {
        ProblemModel::mForm('form');
    }

    /**
     * 修改问题
     * @auth true
     */
    public function edit()
    {
        ProblemModel::mForm('form');
    }

    /**
     * 删除问题
     * @auth true
     */
    public function remove(){
        $id = request()->param('id',0);
        ProblemModel::where('id','=',$id)->delete();
        $this->success('数据删除成功');
    }


}